package com.lmx.repoDomain.tmodel;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.lmx.repoDomain.tmodel.Dicttype;
import com.lmx.repoDomain.tmodel.Privilege;
import com.lmx.repoDomain.tmodel.business.Organization;
import com.lmx.repoDomain.tmodel.business.User;
import com.lmx.repoDomain.tmodel.BaseEntity;
import com.lmx.repoDomain.tmodel.Role;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiLookupIncludeAutomatically;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

/**
 * 员工表
 */
@Entity
@JsonApiResource(type = "employee")
@Table(name = "tnb_employee")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Employee extends BaseEntity {

	protected Role role;// 角色
	private String name;// 真实姓名
	private String entName;// 企业名称
	private String avatar;// 头像文件名
	private String desc;// 自我描述
	private Short onlineStatus;// 在线状态 0：离线 1：在线
	private Short status;// 状态 0：禁用 1：未认证 2：已认证
	private String weixin;// 微信号
	private String qqnum;// QQ
	private Integer age;// 年龄

	private String introduce;// 简介

	private String regWay;// 注册途径
	private String verifyFailReason;// 审核失败原因

	private String remark; // 备注
	private Organization org; // 备注
	private String authCode;// 验证码

	private String certificateImage;// 证书图片

	private Integer createDateTime;// 创建时间

	private User createUser;// 创建者id

	private String curAddress;// 当前地址

	private Department department;// 需关联部门表

	private String hbeaconID; // 手环id

	private Dicttype hireType;// 雇佣类型

	private Short isGroupFlag;// 是否为护理组成员

	private Short isNurseFlag;// 是否为护工

	private Integer lastUpdateDateTime;// 更新时间

	private User lastUpdateUser;// 更新者id

	private String profession;// 专业

	private String schoolName;// 学校名称

	private Integer staffBirth;// 生日

	private String staffTel;

	private String staffCardCode;// 身份证

	private Dicttype staffCensus;// 户籍

	private String certificateName;// 证书名称

	private String staffContactName;// 联系人名字

	private Dicttype staffContactRelation;// 联系人关系

	private String staffContactTel;// 联系人手机

	private Dicttype staffEducation;// 学历

	private String staffMail;// 邮箱

	private Dicttype staffMaritalStatus;// 婚姻状态

	// private String staffName;// 名称

	private Dicttype staffNation;// 民族

	private Dicttype staffSex;// 性别

	private Dicttype staffStatus;// 职工状态

	private Integer toPositionDate;// 到岗时间

	private Privilege privilege;// 权限

	private List<User> systemusers;// 挂接系统用户表

	private Integer contractEndDate;// 合同截止时间

	private String special;// 特长

	private String qualificationType;// 职业资格

	private Dicttype position;// 职位

	private List<Customer> customers;// 所对应老人

	private Short leaderFlag;

	private Device bracelet;
	
	private Town town;// 区县
	
	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT) // huibati
	@JoinColumn(name = "town_id", foreignKey = @ForeignKey(name = "null"))
	public Town getTown() {
		return town;
	}

	public void setTown(Town town) {
		this.town = town;
	}
	
	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "bracelet_id", nullable = true, foreignKey = @ForeignKey(name = "null"))
	public Device getBracelet() {
		return bracelet;
	}

	public void setBracelet(Device bracelet) {
		this.bracelet = bracelet;
	}

	@Column(name = "leader_flag", columnDefinition = "smallint default 0 COMMENT '是否是部门领导'")
	public Short getLeaderFlag() {
		return leaderFlag;
	}

	public void setLeaderFlag(Short leaderFlag) {
		if (leaderFlag == null)
			leaderFlag = 0;
		this.leaderFlag = leaderFlag;
	}

	@JsonApiToMany
	@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	@JoinTable(name = "tnb_employee_customer", joinColumns = {
			@JoinColumn(name = "employee_id", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "null")) }, inverseJoinColumns = {
					@JoinColumn(name = "customer_id", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "null")) })
	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "position_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getPosition() {
		return position;
	}

	public void setPosition(Dicttype position) {
		this.position = position;
	}

	@Column(name = "contract_enddate")
	public Integer getContractEndDate() {
		return contractEndDate;
	}

	public void setContractEndDate(Integer contractEndDate) {
		this.contractEndDate = contractEndDate;
	}

	@Column(name = "special")
	public String getSpecial() {
		return special;
	}

	public void setSpecial(String special) {
		this.special = special;
	}

	@Column(name = "qualification_type")
	public String getQualificationType() {
		return qualificationType;
	}

	public void setQualificationType(String qualificationType) {
		this.qualificationType = qualificationType;
	}

	@JsonApiToMany
	// @Fetch(FetchMode.SELECT)
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "employee")
	public List<User> getSystemusers() {
		return systemusers;
	}

	public void setSystemusers(List<User> systemusers) {
		this.systemusers = systemusers;
	}

	@Column(name = "staffTel")
	public String getStaffTel() {
		return staffTel;
	}

	public void setStaffTel(String staffTel) {
		this.staffTel = staffTel;
	}

	@Column(name = "certificateImage")
	public String getCertificateImage() {
		return certificateImage;
	}

	public void setCertificateImage(String certificateImage) {
		this.certificateImage = certificateImage;
	}

	@Column(name = "createDateTime")
	public Integer getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "createUser_id", foreignKey = @ForeignKey(name = "null"))
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@Column(name = "hbeaconID")
	public String getHbeaconID() {
		return hbeaconID;
	}

	public void setHbeaconID(String hbeaconID) {
		this.hbeaconID = hbeaconID;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "hireType_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getHireType() {
		return hireType;
	}

	public void setHireType(Dicttype hireType) {
		this.hireType = hireType;
	}

	@Column(name = "isGroupFlag")
	public Short getIsGroupFlag() {
		return isGroupFlag;
	}

	public void setIsGroupFlag(Short isGroupFlag) {
		if (isGroupFlag == null)
			isGroupFlag = 0;
		this.isGroupFlag = isGroupFlag;
	}

	@Column(name = "isNurseFlag")
	public Short getIsNurseFlag() {
		return isNurseFlag;
	}

	public void setIsNurseFlag(Short isNurseFlag) {
		if (isNurseFlag == null)
			isNurseFlag = 0;
		this.isNurseFlag = isNurseFlag;
	}

	@Column(name = "lastUpdateDateTime")
	public Integer getLastUpdateDateTime() {
		return lastUpdateDateTime;
	}

	public void setLastUpdateDateTime(Integer lastUpdateDateTime) {
		this.lastUpdateDateTime = lastUpdateDateTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "lastUpdateUser_id", foreignKey = @ForeignKey(name = "null"))
	public User getLastUpdateUser() {
		return lastUpdateUser;
	}

	public void setLastUpdateUser(User lastUpdateUser) {
		this.lastUpdateUser = lastUpdateUser;
	}

	@Column(name = "profession")
	public String getProfession() {
		return profession;
	}

	public void setProfession(String profession) {
		this.profession = profession;
	}

	@Column(name = "schoolName")
	public String getSchoolName() {
		return schoolName;
	}

	public void setSchoolName(String schoolName) {
		this.schoolName = schoolName;
	}

	@Column(name = "staffBirth")
	public Integer getStaffBirth() {
		return staffBirth;
	}

	public void setStaffBirth(Integer staffBirth) {
		this.staffBirth = staffBirth;
	}

	@Column(name = "staffCardCode")
	public String getStaffCardCode() {
		return staffCardCode;
	}

	public void setStaffCardCode(String staffCardCode) {
		this.staffCardCode = staffCardCode;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "staffCensus_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStaffCensus() {
		return staffCensus;
	}

	public void setStaffCensus(Dicttype staffCensus) {
		this.staffCensus = staffCensus;
	}

	@Column(name = "certificateName")
	public String getCertificateName() {
		return certificateName;
	}

	public void setCertificateName(String certificateName) {
		this.certificateName = certificateName;
	}

	@Column(name = "staffContactName")
	public String getStaffContactName() {
		return staffContactName;
	}

	public void setStaffContactName(String staffContactName) {
		this.staffContactName = staffContactName;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "staffContactRelation_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStaffContactRelation() {
		return staffContactRelation;
	}

	public void setStaffContactRelation(Dicttype staffContactRelation) {
		this.staffContactRelation = staffContactRelation;
	}

	@Column(name = "staffContactTel")
	public String getStaffContactTel() {
		return staffContactTel;
	}

	public void setStaffContactTel(String staffContactTel) {
		this.staffContactTel = staffContactTel;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "staffEducation_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStaffEducation() {
		return staffEducation;
	}

	public void setStaffEducation(Dicttype staffEducation) {
		this.staffEducation = staffEducation;
	}

	@Column(name = "staffMail")
	public String getStaffMail() {
		return staffMail;
	}

	public void setStaffMail(String staffMail) {
		this.staffMail = staffMail;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "staffMaritalStatus_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStaffMaritalStatus() {
		return staffMaritalStatus;
	}

	public void setStaffMaritalStatus(Dicttype staffMaritalStatus) {
		this.staffMaritalStatus = staffMaritalStatus;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "staffNation_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStaffNation() {
		return staffNation;
	}

	public void setStaffNation(Dicttype staffNation) {
		this.staffNation = staffNation;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "staffSex_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStaffSex() {
		return staffSex;
	}

	public void setStaffSex(Dicttype staffSex) {
		this.staffSex = staffSex;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "staffStatus_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStaffStatus() {
		return staffStatus;
	}

	public void setStaffStatus(Dicttype staffStatus) {
		this.staffStatus = staffStatus;
	}

	@Column(name = "toPositionDate")
	public Integer getToPositionDate() {
		return toPositionDate;
	}

	public void setToPositionDate(Integer toPositionDate) {
		this.toPositionDate = toPositionDate;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "privilege_id", foreignKey = @ForeignKey(name = "null"))
	public Privilege getPrivilege() {
		return privilege;
	}

	public void setPrivilege(Privilege privilege) {
		this.privilege = privilege;
	}

	/*
	 * @JsonApiToOne
	 * 
	 * @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	 * 
	 * @Fetch(FetchMode.JOIN)
	 * 
	 * @JoinColumn(name = "nurseGroup_id", foreignKey = @ForeignKey(name =
	 * "null")) public NurseGroup getNurseGroup() { return nurseGroup; }
	 * 
	 * public void setNurseGroup(NurseGroup nurseGroup) { this.nurseGroup =
	 * nurseGroup; }
	 */

	@JsonApiToOne
	// @JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "org_id", foreignKey = @ForeignKey(name = "null"))
	public Organization getOrg() {
		return org;
	}

	public void setOrg(Organization org) {
		this.org = org;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "role_id", foreignKey = @ForeignKey(name = "null"))
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	@Column(name = "ent_name")
	public String getEntName() {
		return entName;
	}

	public void setEntName(final String entName) {
		this.entName = entName;
	}

	@Column(name = "avatar")
	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(final String avatar) {
		this.avatar = avatar;
	}

	@Column(name = "descr")
	public String getDesc() {
		return desc;
	}

	public void setDesc(final String desc) {
		this.desc = desc;
	}

	@Column(name = "online_status")
	public Short getOnlineStatus() {
		return onlineStatus;
	}

	public void setOnlineStatus(Short onlineStatus) {
		this.onlineStatus = onlineStatus;
	}

	@Column(name = "status")
	public Short getStatus() {
		return status;
	}

	public void setStatus(final Short status) {
		this.status = status;
	}

	@Column(name = "weixin")
	public String getWeixin() {
		return weixin;
	}

	public void setWeixin(final String weixin) {
		this.weixin = weixin;
	}

	@Column(name = "qqnum")
	public String getQqnum() {
		return qqnum;
	}

	public void setQqnum(String qqnum) {
		this.qqnum = qqnum;
	}

	@Column(name = "curaddress")
	public String getCurAddress() {
		return curAddress;
	}

	public void setCurAddress(final String curAddress) {
		this.curAddress = curAddress;
	}

	@Column(name = "age")
	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	@Column(name = "introduce")
	public String getIntroduce() {
		return introduce;
	}

	public void setIntroduce(String introduce) {
		this.introduce = introduce;
	}

	@Column(name = "reg_way")
	public String getRegWay() {
		return regWay;
	}

	public void setRegWay(String regWay) {
		this.regWay = regWay;
	}

	@Column(name = "verify_fail_reason")
	public String getVerifyFailReason() {
		return verifyFailReason;
	}

	public void setVerifyFailReason(String verifyFailReason) {
		this.verifyFailReason = verifyFailReason;
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Transient
	public String getAuthCode() {
		return authCode;
	}

	public void setAuthCode(String authCode) {
		this.authCode = authCode;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "department_id", foreignKey = @ForeignKey(name = "null"))
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}
}